package com.xinfu.newproject.adapter.complaint_adapter;


import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xinfu.newproject.R;
import com.xinfu.newproject.bean.complaint.bean.ComplaintDetailBean;
import com.xinfu.newproject.ui.complaint_feedback.ComplaintDetailsFragment;
import com.xinfu.newproject.widget.picture.ViewPagerActivity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * https://github.com/CymChad/BaseRecyclerViewAdapterHelper
 */
public class ComplaintDetailAdapter extends BaseQuickAdapter<ComplaintDetailBean.ResultBean.ComplaintStatusListBean, BaseViewHolder> {

    private String name, time, type;
    private RecyclerView mRecyclerView;
    private ComplaintImageAdapter complaintImageAdapter;

    public ComplaintDetailAdapter() {
        super(R.layout.recycler_complaint_detail);

    }

    public void detail(String name, String time, String type) {
        this.name = name;
        this.time = time;
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, ComplaintDetailBean.ResultBean.ComplaintStatusListBean item) {
        mRecyclerView = helper.getView(R.id.recycler_complaint_detail_rv);
        mRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        complaintImageAdapter = new ComplaintImageAdapter();
        mRecyclerView.setAdapter(complaintImageAdapter);
        complaintImageAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Bundle bundle1 = new Bundle();
                bundle1.putString("picture", item.getPicture());
                bundle1.putInt("position", position);
                ((ComplaintDetailsFragment) mContext).startIntentActivityAnim(ViewPagerActivity.class, view, bundle1);
            }
        });
        if (item.getPicture() != null) {
            if (item.getPicture().length() > 5) {
                mRecyclerView.setVisibility(View.VISIBLE);
                if (item.getPicture().contains(";")) {
                    String[] imageSS = item.getPicture().split(";");
                    complaintImageAdapter.setNewData(Arrays.asList(imageSS));
                } else {
                    List<String> list = new ArrayList<>();
                    list.add(item.getPicture());
                    complaintImageAdapter.setNewData(list);
                }
            } else {
                mRecyclerView.setVisibility(View.GONE);
            }
        } else {
            mRecyclerView.setVisibility(View.GONE);
        }
        switch (item.getStatus()) {
            case 100:
                helper.setText(R.id.recycler_complaint_detail_status, "待受理");
                helper.setTextColor(R.id.recycler_complaint_detail_status, mContext.getResources().getColor(R.color.blue_4a));
                helper.getView(R.id.recycler_complaint_detail_contents).setVisibility(View.GONE);
                if (type.equals("1")) {
                    helper.setText(R.id.recycler_complaint_detail_name, "投诉人:" + name);
                    helper.setText(R.id.recycler_complaint_detail_time, "投诉时间:" + time);
                } else {
                    helper.setText(R.id.recycler_complaint_detail_name, "建议人:" + name);
                    helper.setText(R.id.recycler_complaint_detail_time, "建议时间:" + time);
                }

                break;
            case 200:
                helper.setText(R.id.recycler_complaint_detail_status, "已受理");
                helper.setTextColor(R.id.recycler_complaint_detail_status, mContext.getResources().getColor(R.color.blue_4a));
                helper.getView(R.id.recycler_complaint_detail_contents).setVisibility(View.VISIBLE);
                helper.setText(R.id.recycler_complaint_detail_name, "受理人: " + item.getHandRealName());
                helper.setText(R.id.recycler_complaint_detail_time, "受理时间: " + item.getCreateTime());
                helper.setText(R.id.recycler_complaint_detail_contents, "受理回复: " + item.getReturnContents());
                break;
            case 300:
                helper.setText(R.id.recycler_complaint_detail_status, "已评价 一 满意");
                helper.setTextColor(R.id.recycler_complaint_detail_status, mContext.getResources().getColor(R.color.blue_4a));
                helper.getView(R.id.recycler_complaint_detail_contents).setVisibility(View.VISIBLE);
                if (type.equals("1")) {
                    helper.setText(R.id.recycler_complaint_detail_name, "投诉人:" + name);
                    helper.setText(R.id.recycler_complaint_detail_time, "评价时间:" + item.getCreateTime());
                } else {
                    helper.setText(R.id.recycler_complaint_detail_name, "建议人:" + name);
                    helper.setText(R.id.recycler_complaint_detail_time, "建议时间:" + time);
                }
//                helper.setText(R.id.recycler_complaint_detail_name, "处理人: " + item.getHandRealName());
//                helper.setText(R.id.recycler_complaint_detail_time, "处理时间: " + item.getCreateTime());
                helper.setText(R.id.recycler_complaint_detail_contents, "评价内容: " + item.getReturnContents());
                break;
            case 400:
                helper.setText(R.id.recycler_complaint_detail_status, "已评价 一 不满意");
                helper.setTextColor(R.id.recycler_complaint_detail_status, mContext.getResources().getColor(R.color.blue_4a));
                helper.getView(R.id.recycler_complaint_detail_contents).setVisibility(View.VISIBLE);
                if (type.equals("1")) {
                    helper.setText(R.id.recycler_complaint_detail_name, "投诉人:" + name);
                    helper.setText(R.id.recycler_complaint_detail_time, "评价时间:" + item.getCreateTime());
                } else {
                    helper.setText(R.id.recycler_complaint_detail_name, "建议人:" + name);
                    helper.setText(R.id.recycler_complaint_detail_time, "建议时间:" + time);
                }
//                helper.setText(R.id.recycler_complaint_detail_name, "处理人: " + item.getHandRealName());
//                helper.setText(R.id.recycler_complaint_detail_time, "处理时间: " + item.getCreateTime());
                helper.setText(R.id.recycler_complaint_detail_contents, "评价内容: " + item.getReturnContents());
                break;

        }
        if (item.getPosition() == 0) {
            helper.setTextColor(R.id.recycler_complaint_detail_status, mContext.getResources().getColor(R.color.location_color));
            helper.setTextColor(R.id.recycler_complaint_detail_name, mContext.getResources().getColor(R.color.location_color));
            helper.setTextColor(R.id.recycler_complaint_detail_time, mContext.getResources().getColor(R.color.location_color));
            helper.setTextColor(R.id.recycler_complaint_detail_contents, mContext.getResources().getColor(R.color.location_color));
            helper.setImageResource(R.id.recycler_repair_complaint_progress_iv, R.mipmap.repair_rot);
        } else {
            helper.setTextColor(R.id.recycler_complaint_detail_status, mContext.getResources().getColor(R.color.gray_a5));
            helper.setTextColor(R.id.recycler_complaint_detail_name, mContext.getResources().getColor(R.color.gray_a5));
            helper.setTextColor(R.id.recycler_complaint_detail_time, mContext.getResources().getColor(R.color.gray_a5));
            helper.setTextColor(R.id.recycler_complaint_detail_contents, mContext.getResources().getColor(R.color.gray_a5));
            helper.setImageResource(R.id.recycler_repair_complaint_progress_iv, R.mipmap.repair_gray_rot);
        }

    }

}